﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Http;

namespace ETA.Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

    public class MultiLangRouteHandler : MvcRouteHandler {
          protected override IHttpHandler GetHttpHandler(RequestContext requestContext) {
              var langCookie = requestContext.HttpContext.Request.Cookies["Localization.CultureName"];
              if (langCookie != null)
              {
                  Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value);
                  Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value);
              }
            return base.GetHttpHandler(requestContext);
        }
    }
}